package com.wc.service.impl;

import com.wc.dao.EmpDao;
import com.wc.dao.impl.EmpDaoImpl;
import com.wc.domain.Emp;
import com.wc.service.EmpService;
import com.wc.utils.Md5Util;

/**
 * @ClassName:EmpServiceImpl
 * @Author: 鹿建文
 * @Date: 2022/3/23  - 11:44
 * @Describe:
 */
public class EmpServiceImpl implements EmpService {
    private EmpDao empDao  = new EmpDaoImpl();
    @Override
    public int login(String account, String password) {
        int empno = empDao.selectEmpnoByAccount(account);
        if (empno==-1){
            return -1;
        }
        Emp emp = empDao.selectEmpByEmpno(empno);
        String encode = Md5Util.encode(password, emp.getSalt());
        if ((emp.getPassword().equals(encode))){
            return empno;
        }
        return -1;
    }

    @Override
    public Emp getEmpByEmpno(Integer empno) {
        Emp emp = empDao.selectEmpByEmpno(empno);
        return emp;

    }

    @Override
    public String updateEmp(Emp emp) {
        boolean res = empDao.updateEmp(emp);
        return res? "succeed":"false";
    }
}
